package com.ntschy.common.valid.dateRange;


import cn.hutool.core.util.StrUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class DateRangeValidation implements ConstraintValidator<DateRange, String> {

    private boolean must;

    @Override
    public void initialize(DateRange constraintAnnotation) {
        boolean must = constraintAnnotation.must();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        if(!must && value == null) {
            return true;
        } else {
            if (StrUtil.isEmpty(value)) {
                return false;
            } else {
                return DateRangeValidationUtil.isDateRange(value);
            }
        }

    }
}
